package com.pro01.backend.config;

import com.pro01.backend.interceptor.JwtInterceptor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

@Configuration
public class WebConfig implements WebMvcConfigurer {

    @Autowired
    private JwtInterceptor jwtInterceptor;

    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        registry.addInterceptor(jwtInterceptor)
                .addPathPatterns("/users/**")  // 保护所有 /users/** 相关接口
                .excludePathPatterns(
                        "/users/login",
                        "/users/register",
                        "/users/sendEmailCode",
                        "/users/leaderboard/credit",
                        "/users/leaderboard/ratio"); // 登录和注册不拦截
    }
}
